package com.lagou.rpc.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

/**
 * 服务
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Server implements Serializable{
    //服务ip
    String ip;
    //服务端口号
    Integer port;


    //相应时间
    Long time;
    //最后访问时间
    Date date;

    /**
     * 设置相应时间
     * @param time
     */
    public void setTime(long time){
        this.time = time;
        this.date = new Date();
    }

    /**
     * 清空时间
     */
    public synchronized void cleanTime(){
        this.time = null;
    }

    @Override
    public String toString() {
        return "Server{" +
                "ip='" + ip + '\'' +
                ", port=" + port +
                ", time=" + time +
                ", date=" +(date==null?null: date.toLocaleString()) +
                '}';
    }
}
